﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Com.DAO;
using Com.UI.Web;

namespace WF.Web.Pages.Workflow.KQ
{
    public partial class Attachment : System.Web.UI.Page
    {
        public Com.DAO.DataManager mobjDB = new DataManager();
        public string KQApplyID;

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                KQApplyID = Request.QueryString.Get("KQAPPLYID");

                this.LoadImage();
            }
            catch (Exception ex)
            {                
                throw new Exception("读取考勤附件信息=>附件信息加载出错：" + ex.Message);
            }
        }

        private void LoadImage()
        {
            try
            {
                string sql = "";
                sql = sql + "Select ID As RowID, ID As ImageID From Attachment Where EntityID='" + KQApplyID + "'";

                this.mobjDB.OpenWithConfig();
                DataSet ds = this.mobjDB.SelectDataSet(sql);
                this.mobjDB.Close();
                dtList.DataSource = ds.Tables[0].DefaultView;
                dtList.DataBind();
                
            }
            catch { }
        }

        protected void dtList_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            try
            {
                if (e.Item.ItemIndex >= 0)
                {
                    Image img = (Image)e.Item.FindControl("imgPhoto");
                    string imageID = DataBinder.Eval(e.Item.DataItem, "ImageID").ToString();
                    //img.ImageUrl = "~/SystemSetting/frmShowImage.aspx?id=" + imageID;
                    img.ImageUrl = "../../../Attachment/ShowThumbImage.aspx?id=" + imageID;

                    HiddenField txt = (HiddenField)e.Item.FindControl("txtImageID");
                    txt.Value = imageID;

                    CheckBoxEx chk = (CheckBoxEx)e.Item.FindControl("chkSel");
                    //if (CheckRight(RightItem.Estate.PictureMovieInfo.Modify.All)
                    //    || CheckRight(RightItem.Estate.PictureMovieInfo.Modify.Dept)
                    //    || CheckEstateRight(RightItem.Estate.PictureMovieInfo.Modify.Estate)
                    //)
                    //{
                        chk.Visible = true;
                    //}
                    //else
                    //{
                    //    chk.Visible = false;
                    //}

                    //if (IsReadonly == "1")
                    //{
                    //    chk.Visible = false;
                    //}

                    string sFlagDefault = DataBinder.Eval(e.Item.DataItem, "FlagDefault").ToString();
                    if (sFlagDefault == "1")
                    {
                        Label lbl = (Label)e.Item.FindControl("lblDescription");
                        lbl.ForeColor = System.Drawing.Color.Red;
                    }
                }
            }
            catch (Exception ex)
            {
                //this.ShowMessage(ex);
            }
        }
    }
}